/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ACRestWebService;

import AjouConquerorBeans.BuildingSateInRBean;
import Classes.ABuildingInR;
import Classes.BuildingsInR;
import data.BuildingEntity;
import data.BuildingEntityFacade;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.enterprise.context.RequestScoped;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.ws.rs.POST;

/**
 * REST Web Service
 *
 * @author ajou
 */
@Path("building")
@RequestScoped
public class BuildingREST {
    BuildingSateInRBean building = lookupBuildingSateInRBeanBean();
    BuildingEntityFacade bef = lookupBuildingEntityFacadeBean();

    @Context
    private UriInfo context;

    /**
     * Creates a new instance of BuildingREST
     */
    public BuildingREST() {
    }
    @POST
    @Path("state")
    @Produces("application/json")
    @Consumes("application/json")
    public ArrayList<ABuildingInR> getGameover(String roomid) {
        int r = Integer.parseInt(roomid);
        return building.getBuildings(r).getBuilinds();
    }
    /**
     * Retrieves representation of an instance of ACRestWebService.BuildingREST
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("application/json")
    public List<BuildingEntity> getJson() {
        List<BuildingEntity> buildings = bef.findAll();
        return buildings;
    }

    /**
     * PUT method for updating or creating an instance of BuildingREST
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("application/json")
    public void putJson(String content) {
    }

    private BuildingEntityFacade lookupBuildingEntityFacadeBean() {
        try {
            javax.naming.Context c = new InitialContext();
            return (BuildingEntityFacade) c.lookup("java:global/AjouConquerorServer/AjouConquerorServer-ejb/BuildingEntityFacade!data.BuildingEntityFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    private BuildingSateInRBean lookupBuildingSateInRBeanBean() {
        try {
            javax.naming.Context c = new InitialContext();
            return (BuildingSateInRBean) c.lookup("java:global/AjouConquerorServer/AjouConquerorServer-ejb/BuildingSateInRBean!AjouConquerorBeans.BuildingSateInRBean");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
